package com.xtayfjpk.spring.security.test.servlet;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.Filter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.web.FilterChainProxy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.stereotype.Controller;

import com.xtayfjpk.spring.security.test.service.CustomerService;
import com.xtayfjpk.spring.security.test.service.MyService;

@Controller("myServlet")
public class MyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@Resource
	private MyService myService;
	@Resource(name="springSecurityFilterChain")
	private Filter filter;
	@Resource
	private CustomerService customerService;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)	throws ServletException, IOException {
		System.out.println(filter.getClass());
		FilterChainProxy chainProxy = (FilterChainProxy) filter;
		for(SecurityFilterChain filterChain : chainProxy.getFilterChains()) {
			System.out.println(filterChain.getFilters());
		}
		
		System.out.println("--------------------------------------");
		System.out.println(customerService.getById(101L));
		req.getRequestDispatcher("/my.jsp").forward(req, resp);
	}
}
